package org.link.zuoye1;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * 
 * project_name:ZuoYe
 * package_name:org.link.zuoye1
 * file_name:Test3.java
 * @author Link
 * create_date:2015年8月10日 下午5:40:03
 * modified_date:
 * description:判断是否是回文
 *
 */
public class Test3 extends JFrame{
	
	private JLabel label1,label2;
	private JTextField field1,field2;
	private JButton bt1;
	
	public Test3(){
		
		this.setSize(300,200);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = this.getSize();
		this.setLocation((int)((screenSize.getWidth()-frameSize.getWidth())/2), (int)(screenSize.getHeight()-frameSize.getHeight())/2);
		this.setTitle("字符串个数统计");
		ImageIcon tp = new ImageIcon(Test1.class.getResource("/image/2222.jpg"));
		this.setIconImage(tp.getImage());
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗口关闭同时关闭进程
		this.setResizable(false);//设置窗体不可放大
		
		this.setLayout(null);
		
		label1 = new JLabel("字符串");
		label1.setBounds(58, 20, 80, 20);
		this.add(label1);
		
		label2 = new JLabel("结果");
		label2.setBounds(195, 20, 80, 20);
		this.add(label2);
		
		field1 = new JTextField();
		field1.setBounds(30, 45, 100, 30);
		field1.setHorizontalAlignment(JTextField.CENTER);//设置文本框居中
		field1.setFont(new Font("微软雅黑",Font.ROMAN_BASELINE,12));
		this.add(field1);
		
		field2 = new JTextField();
		field2.setBounds(175, 45, 75, 30);
		field2.setHorizontalAlignment(JTextField.CENTER);//设置文本框居中
		field2.setFont(new Font("微软雅黑",Font.ROMAN_BASELINE,14));
		this.add(field2);
		
		bt1 = new JButton("是否是回文");
		bt1.setBounds(80, 100, 100, 35);
		bt1.setMargin(new Insets(0,0,0,0));//设置按钮的边缘空余部分为0
		this.add(bt1);
		bt1.addActionListener(new ActionListener() {//判断是否是回文方法
			
			@Override
			public void actionPerformed(ActionEvent e) {
				StringBuffer sf = new StringBuffer(field1.getText()).reverse();
				if(field1.getText().equals(sf.toString())){
					field2.setText("是回文");
				}else{
					field2.setText("不是回文");
				}
				
			}
		});
		
	}
	
	public static void main(String[] args) {
		Test3 t3 = new Test3();
		t3.setVisible(true);
		
	}
}



